﻿using System;
using System.Collections.Generic;
using WS.EKA.DataAccess;
using WS.EKA.Model;
using WS.EKA.ServiceInterface;

namespace WS.EKA.ServiceImpl
{
    public class CollectService : ICollect
    {
        public void Add(Collect collect)
        {
            var existCollect = CollectContecxt.Get(x => x.ProductGuid == collect.ProductGuid && x.MemLoginID == collect.MemLoginID);
            if (existCollect != null)
            {
                return;
            }
            var result = CollectContecxt.Add(collect);
            if (result != 1)
            {
                throw new Exception("收藏失败.商品ID:" + collect.ProductGuid);
            }

        }

        public List<Collect> Get(string MemLoginID)
        {
            return CollectContecxt.GetByConditions(x => x.MemLoginID == MemLoginID);
        }

        public void Delete(Guid id, string memLoginID)
        {
            var result = CollectContecxt.Delete(id, memLoginID);
            if (result != 1)
            {
                throw new Exception("删除收藏失败.Guid:" + id);
            }
        }
    }
}
